package com.imti.mall.product.controller;

import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.pms.pojo.PmsProductLadder;
import com.imti.mall.product.service.PmsProductCategoryService;
import com.imti.mall.product.service.PmsProductLadderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/product")
public class PmsProductLadderController {
    @Autowired
    PmsProductLadderService pmsProductLadderService;

    /**
     * 根据商品id查询商品梯价优惠
     * @param id
     * @return
     */
    @RequestMapping("/getPmsProductLadderProductId/{id}")
    public CommonResult getPmsProductLadderProductId(@PathVariable("id") Integer id) {
        List<PmsProductLadder> pmsProductLadderProductId = pmsProductLadderService.getPmsProductLadderProductId(id);
        if(pmsProductLadderProductId!=null){
            return CommonResult.success(pmsProductLadderProductId);
        }else {
            return CommonResult.failed("失败");
        }

    }
    /**
     * 根据梯价表id修改满减表
     * @param pmsProductLadder
     * @return
     */
    @RequestMapping("/upadtePmsProductLadder")
    public CommonResult upadtePmsProductLadder(PmsProductLadder pmsProductLadder) {
        Integer integer = pmsProductLadderService.upadtePmsProductLadder(pmsProductLadder);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 查询全部商品阶梯价格表
     * @return
     */
    @RequestMapping("/findPmsProductLadder")
    public CommonResult findPmsProductLadder() {
        List<PmsProductLadder> pmsProductLadder = pmsProductLadderService.findPmsProductLadder();
        if(pmsProductLadder!=null){
            return CommonResult.success(pmsProductLadder);
        }else {
            return CommonResult.failed("失败");
        }

    }
    /**
     * 根据接替id查询商品阶梯价格表
     * @return
     */
    @RequestMapping("/findPmsProductLadderById/{id}")
    public CommonResult findPmsProductLadderById(@PathVariable("id") Integer id) {
        PmsProductLadder pmsProductLadderById = pmsProductLadderService.findPmsProductLadderById(id);
        if(pmsProductLadderById!=null){
            return CommonResult.success(pmsProductLadderById);
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 添加商品阶梯价格表
     * @return
     */
    @RequestMapping("/addPmsProductLadder")
    public CommonResult addPmsProductLadder(PmsProductLadder pmsProductLadder) {
        Integer integer = pmsProductLadderService.addPmsProductLadder(pmsProductLadder);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据商品阶梯价格表id删除
     * @return
     */
    @RequestMapping("/delPmsProductLadder/{id}")
    public CommonResult delPmsProductLadder(@PathVariable("id") Integer id) {
        Integer integer = pmsProductLadderService.delPmsProductLadder(id);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }


    }
}
